<?php
/**
 * Created by PhpStorm.
 * User: yss
 * Date: 2018/1/19
 * Time: 15:28
 */

namespace backend\controllers;


use backend\components\event\MailEvent;
use yii\helpers\Url;
use yii\web\Controller;

/**
 * 发送邮件
 * Class SendMailController
 * @package backend\controllers
 */
class SendMailController extends Controller
{
    const SEND_MAIL = 'send_mail';

    public function init()
    {
        parent::init();

        // 绑定邮件类，当时间出发时，调用定义的邮件类
        $this->on(self::SEND_MAIL, ['backend\components\Mail', 'sendMail']);
    }

    public function actionSend()
    {
        // 构建需要发送的内容
        $event = new MailEvent();
        $event->email = 'liuzhenqing173@163.com';
        $event->subject = '事件邮件测试1111';
        $event->content = '<html><head></head><body><h1>请点击连接激活</h1><h3><a href=\'http://admin.blog.com/test/index.html\'>http://admin.blog.com/test/index.html</href></h3></body></html>';
        // 触发邮件事件
        $this->trigger(self::SEND_MAIL, $event);
    }
}